package logic

import (
	"cart_srv/models/redis"
	"context"
	"errors"

	"cart_srv/cart_srv"
	"cart_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDelCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelCartLogic {
	return &DelCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DelCartLogic) DelCart(in *cart_srv.DelCartRequest) (*cart_srv.DelCartResponse, error) {
	// todo: add your logic here and delete this line
	if redis.CartIsNilOrNotNil(int(in.UserId)) {
		return nil, errors.New("购物车为空")
	}
	err := redis.DelCart(int(in.UserId), int(in.ShopId))
	if err != nil {
		return nil, errors.New("购物车删除失败")
	}
	return &cart_srv.DelCartResponse{}, nil
}
